unit procuraconta;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;

type
  TFProcuraConta = class(TForm)
    DataSource1: TDataSource;
    Query1: TQuery;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Query1codigo: TStringField;
    Query1nome: TStringField;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FProcuraConta: TFProcuraConta;

implementation

{$R *.dfm}

procedure TFProcuraConta.Button2Click(Sender: TObject);
begin
close;
end;

procedure TFProcuraConta.Button1Click(Sender: TObject);
begin
button2.Visible := false;
query1.First;
edit1.font.Color := clred;
while not query1.eof do
 begin
 if pos(edit1.text,query1nome.value) > 0 then
    begin
    edit1.Text := query1codigo.value + ' - ' + query1nome.Value;
    edit1.font.Color := clblue;
    button2.Visible := true;
    break;
 end;
 query1.next;
end;
exit;

end;
procedure TFProcuraConta.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
     SelectNext(ActiveControl,true,true);
  if key=#27 then
     close;

end;

end.
